<template>
  <div>

<h1>用户注册</h1>
<p>用户名：<input type="text" v-model="username"></p>
<p>密&emsp;码：<input type="password" v-model="password1"></p>
<p>密&emsp;码：<input type="password" v-model="password2"></p>
<p>电话号：<input type="text" v-model="phone"></p>
<p>图&emsp;片：<input type="file" id='img'></p>
<p><input type="button" value="注册" @click="register"></p>
  </div>
</template>

<script>
export default {
    data(){
        return {
            username:'',
            password2:'',
            password1:'',
            phone:'',
        }
    },
    methods:{
        register(){
            var file=document.getElementById('img').files[0]
            let fdata=new FormData()
            fdata.append('username',this.username)
            fdata.append('password2',this.password2)
            fdata.append('password1',this.password1)
            fdata.append('phone',this.phone)
            fdata.append('img',file)
            this.axios({
                url:'/app01/register/',
                method:'post',
                data:fdata
            }).then(resp=>{
                console.log(resp.data)
                if(resp.data.code==200){
                    this.$router.push({path:'/login'})
                }
            })
        }
    }
}
</script>

<style>

</style>